package com.wh.springkafka.wechat.controller;

import com.alibaba.fastjson.JSON;
import com.wh.springkafka.wechat.common.BaseResponseVO;
import com.wh.springkafka.wechat.config.WechatTemplateProperties;
import com.wh.springkafka.wechat.service.WechatTemplateServiceImpl;
import com.wh.springkafka.wechat.util.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1")
public class WechatTemplateController {

    @Autowired
    private WechatTemplateProperties properties;

    @Autowired
    private WechatTemplateServiceImpl wechatTemplateService;

    @RequestMapping("/getTemplate")
    public BaseResponseVO getTemplate(){
        return BaseResponseVO.success(FileUtils.readFile2JsonObject(wechatTemplateService.getWechatTemplate().getTemplateFilePath()));
    }
    @RequestMapping("/getTemplateStatistics")
    public BaseResponseVO getTemplateStatistics(@RequestParam(required = false) String id){
        return BaseResponseVO.success(wechatTemplateService.templateStatistics(id));
    }
    @RequestMapping("/dateReported")
    public BaseResponseVO dateReported(@RequestParam(required = false) String body){
        wechatTemplateService.templateReported(JSON.parseObject(body));
        return BaseResponseVO.success();
    }
}
